package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	//for 初始化;条件判断;条件变化{}
	sum := 0
	for i := 1; i <= 10000; i++ {
		sum += i
	}
	fmt.Println("sum = ", sum)
	str := "abc"
	for i := 0; i < len(str); i++ {
		fmt.Printf("str[%d],%c \n", i, str[i])
	}
	//迭代元素，一个元素的位置，一个元素本身
	for i, data := range str {
		fmt.Printf("str[%d],%c \n", i, data)
	}

	for i := range str {
		fmt.Printf("str[%d],%c \n", i, str[i])
	}

	for i, _ := range str {
		fmt.Printf("str[%d],%c \n", i, str[i])
	}
	// 0至100 求和
	s := 0
	for i := 0; i <= 100; i++ {
		s += i
	}
	fmt.Printf("0-100 求和 %d \n", s)

	for i:=1;i<10 ;i++  {
		for j:=1; j<=i ; j++ {
			fmt.Printf("%d * %d = %d \t", i,j,i *j)
		}
		fmt.Print("\n")
	}

	fmt.Printf("---%v \n", &s)
	var p *int
	p = &s
	fmt.Printf("---%v \n", p)
	fmt.Printf("---%v \n", *p)
	*p = 20
	fmt.Printf("---%v \n", *p)
	fmt.Printf("---%v \n", s)

	rand.Seed(time.Now().Unix())
	var i int
	var counter int
	answer := rand.Intn(100)
	for {
		fmt.Printf("请输入数字 \n")
		fmt.Scan(&i)
		counter++
		if i == answer {
			fmt.Printf("输入正确 \n")
			break
		} else if i > answer {
			fmt.Printf("请输入小一点 \n")
		} else if i < answer {
			fmt.Printf("请输入大一点 \n")
		}

	}
	fmt.Printf("一共输入了 %d 次",counter)

}
